//
//  SFMyMovableView.m
//  TableViewFramework
//
//  Created by 支晓辉 on 16/3/30.
//  Copyright © 2016年 wishselfly. All rights reserved.
//

#import "SFMyMovableView.h"

@interface SFMyMovableView ()
/** 标题标签 */
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end

@implementation SFMyMovableView

#pragma mark - init

- (instancetype)init {
    if (self = [super init]) {
        
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        
    }
    return self;
}

#pragma mark - Life cycle

- (void)awakeFromNib {
    [super awakeFromNib];
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTitleLabel)];
    [self.titleLabel addGestureRecognizer:tapGesture];
    self.titleLabel.userInteractionEnabled = YES;
}

#pragma mark - Private methods

- (void)tapTitleLabel {
    [UIView animateWithDuration:0.2f animations:^{
        CATransform3D t = CATransform3DRotate(CATransform3DIdentity, M_PI, 1.f, 0, 0.f);
        t = CATransform3DScale(t, 0.9f, 0.9f, 1.f);
        t = CATransform3DRotate(t, 0.1f, 0.f, 1.f, 0.f);
        self.titleLabel.layer.transform = t;
        self.titleLabel.layer.shadowColor = [UIColor blueColor].CGColor;
        self.titleLabel.layer.shadowOffset = CGSizeMake(2.f, 2.f);
        self.titleLabel.layer.shadowOpacity = 0.6f;
    } completion:^(BOOL finished) {
        if (finished) {
            [UIView animateWithDuration:0.2f animations:^{
                self.titleLabel.layer.transform = CATransform3DIdentity;
                
                self.titleLabel.layer.shadowColor = [UIColor whiteColor].CGColor;
                self.titleLabel.layer.shadowOffset = CGSizeZero;
                self.titleLabel.layer.shadowOpacity = 0.f;
            }];
        }
    }];
}

#pragma mark - Getters

- (NSString *)title {
    return self.titleLabel.text;
}

#pragma mark - Setters

- (void)setTitle:(NSString *)title {
    self.titleLabel.text = title;
}

@end
